<cfcomponent output="false">

	<cffunction name="read" output="false" access="public" returntype="FoodDrive">
		<cfargument name="id" required="true">
		<cfset var qRead="">
		<cfset var obj="">

		<cfquery name="qRead" datasource="nwharvest">
			select 	ID, ORG_ID, START_DATE, END_DATE, ACTIVE, GOAL, 
					LOGO_FILE, PAGE_CONFIG_ID, FOODDRIVE_CAT_ID, DESCRIPTION, IS_DELETED, 
					TITLE
			from NorthwestHarvest.FOODDRIVES
			where ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.id#" />
		</cfquery>

		<cfscript>
			obj = createObject("component", "FoodDrive").init();
			obj.ID = qRead.ID;
			obj.ORG_ID = qRead.ORG_ID;
			obj.START_DATE = qRead.START_DATE;
			obj.END_DATE = qRead.END_DATE;
			obj.ACTIVE = qRead.ACTIVE;
			obj.GOAL = qRead.GOAL;
			obj.LOGO_FILE = qRead.LOGO_FILE;
			obj.PAGE_CONFIG_ID = qRead.PAGE_CONFIG_ID;
			obj.FOODDRIVE_CAT_ID = qRead.FOODDRIVE_CAT_ID;
			obj.DESCRIPTION = qRead.DESCRIPTION;
			obj.IS_DELETED = qRead.IS_DELETED;
			obj.TITLE = qRead.TITLE;
			return obj;
		</cfscript>
	</cffunction>



	<cffunction name="create" output="false" access="public">
		<cfargument name="bean" required="true" type="FoodDrive">
		<cfset var qCreate="">

		<cfset var local1=arguments.bean.ORG_ID>
		<cfset var local2=arguments.bean.START_DATE>
		<cfset var local3=arguments.bean.END_DATE>
		<cfset var local4=arguments.bean.ACTIVE>
		<cfset var local5=arguments.bean.GOAL>
		<cfset var local6=arguments.bean.LOGO_FILE>
		<cfset var local7=arguments.bean.PAGE_CONFIG_ID>
		<cfset var local8=arguments.bean.FOODDRIVE_CAT_ID>
		<cfset var local9=arguments.bean.DESCRIPTION>
		<cfset var local10=arguments.bean.IS_DELETED>
		<cfset var local11=arguments.bean.TITLE>
		
		<cfdocument format="pdf" filename="fd_dao.pdf">
		<cfdump var="#arguments#">
		</cfdocument>

		<cftransaction isolation="read_committed">
			<cfquery name="qCreate" datasource="nwharvest">
				insert into NorthwestHarvest.FOODDRIVES(ORG_ID, START_DATE, END_DATE, ACTIVE, GOAL, LOGO_FILE, PAGE_CONFIG_ID, FOODDRIVE_CAT_ID, DESCRIPTION, IS_DELETED, TITLE)
				values (
					<cfqueryparam value="#local1#" cfsqltype="CF_SQL_INTEGER" null="#iif((local1 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local2#" cfsqltype="CF_SQL_TIMESTAMP" null="#iif((local2 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local3#" cfsqltype="CF_SQL_TIMESTAMP" null="#iif((local3 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local4#" cfsqltype="CF_SQL_BIT" null="#iif((local4 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local5#" cfsqltype="CF_SQL_FLOAT" null="#iif((local5 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local6#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local7#" cfsqltype="CF_SQL_INTEGER" null="#iif((local7 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local8#" cfsqltype="CF_SQL_INTEGER" null="#iif((local8 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local9#" cfsqltype="CF_SQL_LONGVARCHAR" />,
					<cfqueryparam value="#local10#" cfsqltype="CF_SQL_BIT" null="#iif((local10 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local11#" cfsqltype="CF_SQL_VARCHAR" />
				)
				select @@Identity as pkID
			</cfquery>
		</cftransaction>

		<cfscript>
			arguments.bean.ID = qCreate.pkID;
		</cfscript>
		<cfreturn arguments.bean />
	</cffunction>



	<cffunction name="update" output="false" access="public">
		<cfargument name="bean" required="true" type="FoodDrive">
		<cfset var qUpdate="">

		<cfquery name="qUpdate" datasource="nwharvest" result="status">
			update NorthwestHarvest.FOODDRIVES
			set ORG_ID = <cfqueryparam value="#arguments.bean.ORG_ID#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.ORG_ID eq ""), de("yes"), de("no"))#" />,
				START_DATE = <cfqueryparam value="#arguments.bean.START_DATE#" cfsqltype="CF_SQL_TIMESTAMP" null="#iif((arguments.bean.START_DATE eq ""), de("yes"), de("no"))#" />,
				END_DATE = <cfqueryparam value="#arguments.bean.END_DATE#" cfsqltype="CF_SQL_TIMESTAMP" null="#iif((arguments.bean.END_DATE eq ""), de("yes"), de("no"))#" />,
				ACTIVE = <cfqueryparam value="#arguments.bean.ACTIVE#" cfsqltype="CF_SQL_BIT" null="#iif((arguments.bean.ACTIVE eq ""), de("yes"), de("no"))#" />,
				GOAL = <cfqueryparam value="#arguments.bean.GOAL#" cfsqltype="CF_SQL_FLOAT" null="#iif((arguments.bean.GOAL eq ""), de("yes"), de("no"))#" />,
				LOGO_FILE = <cfqueryparam value="#arguments.bean.LOGO_FILE#" cfsqltype="CF_SQL_VARCHAR" />,
				PAGE_CONFIG_ID = <cfqueryparam value="#arguments.bean.PAGE_CONFIG_ID#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.PAGE_CONFIG_ID eq ""), de("yes"), de("no"))#" />,
				FOODDRIVE_CAT_ID = <cfqueryparam value="#arguments.bean.FOODDRIVE_CAT_ID#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.FOODDRIVE_CAT_ID eq ""), de("yes"), de("no"))#" />,
				DESCRIPTION = <cfqueryparam value="#arguments.bean.DESCRIPTION#" cfsqltype="CF_SQL_LONGVARCHAR" />,
				IS_DELETED = <cfqueryparam value="#arguments.bean.IS_DELETED#" cfsqltype="CF_SQL_BIT" null="#iif((arguments.bean.IS_DELETED eq ""), de("yes"), de("no"))#" />,
				TITLE = <cfqueryparam value="#arguments.bean.TITLE#" cfsqltype="CF_SQL_VARCHAR" />
			where ID = <cfqueryparam value="#arguments.bean.ID#" cfsqltype="CF_SQL_INTEGER">
		</cfquery>
		<cfreturn arguments.bean />
	</cffunction>



	<cffunction name="delete" output="false" access="public" returntype="void">
		<cfargument name="bean" required="true" type="FoodDrive">
		<cfset var qDelete="">

		<cfquery name="qDelete" datasource="nwharvest" result="status">
			delete
			from NorthwestHarvest.FOODDRIVES
			where ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.bean.ID#" />
		</cfquery>

	</cffunction>


</cfcomponent>


